package com.lm.Iterator;

public class NameRepository implements Container{
    private String[] names;

    public NameRepository(String[] names){
        this.names = names;
    }

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    /**
     * 内部迭代器实现类
     */
    private class NameIterator implements Iterator<String>{
        int index;
        @Override
        public boolean hasNext() {
            return index < names.length;
        }

        @Override
        public String next() {
            if(this.hasNext()){
                return names[index++];
            }
            return null;
        }
    }
}
